
#include "RWJsonF.h"


string RWJsonFile::readStr(const string name_read_data_file) {
    read_json(name_file+FORMAT_JSON, pt);
    return pt.get<string>(name_read_data_file);
}

int RWJsonFile::readInt(const string name_read_data_file) {
    read_json(name_file+FORMAT_JSON, pt);
    return pt.get<int>(name_read_data_file);
}

bool RWJsonFile::readBool(const string name_read_data_file) {
    read_json(name_file+FORMAT_JSON, pt);
    return pt.get<bool>(name_read_data_file);
}

vector_str RWJsonFile::readVectorStr(const string name_read_data_file) {
    vector_str a;
    
    read_json(name_file+FORMAT_JSON, pt);
    FOR_PY_ONE(kvp, pt.get_child(name_read_data_file), 
            a.push_back(kvp.second.get_value<string>()));

    return a;
}

vector_int RWJsonFile::readVectorInt(const string name_read_data_file) {
    vector_int a;
    
    read_json(name_file+FORMAT_JSON, pt);
    FOR_PY_ONE(kvp, pt.get_child(name_read_data_file), 
            a.push_back(kvp.second.get_value<int>()));

    return a;
}



void RWJsonFile::write(const string data_write_str, const string name_write_data_file) {
    pt.put(name_write_data_file, data_write_str);
}

void RWJsonFile::write(const int data_write_int, const string name_write_data_file) {
    pt.put(name_write_data_file, data_write_int);
}

void RWJsonFile::write(const bool data_write_bool, const string name_write_data_file) {
    pt.put(name_write_data_file, data_write_bool);
}


void RWJsonFile::write(const vector_str &data_write_vector_str, const string name_write_data_file) {
    FOR_SIZE_T(i, data_write_vector_str.size()) {
        pt.put(name_write_data_file + ".key" +to_string(i), data_write_vector_str[i]);
    }
}

void RWJsonFile::write(const vector_int &data_write_vector_int, const string name_write_data_file) {
    FOR_SIZE_T(i, data_write_vector_int.size()) {
        pt.put(name_write_data_file + ".key" +to_string(i), data_write_vector_int[i]);
    }
}


void RWJsonFile::closeWrite(const string name_write_file) {
    json_parser::write_json(name_write_file + ".json", pt);
}

